<?php

class Familymember_Form_Add extends Engine_Form {
	public function init() {
		$this->setTitle ( 'Add Family Member' )->setDescription ( 'Add a member\'s email address and select a type. You can add upto 5 family members at a time. They have to be added as your friend already.' )->setAttrib ( 'id', 'familyAddForm' );
		
		for($i = 0; $i < 5; $i ++) {
			$this->addElement ( 'Text', 'email' . $i, array ('label' => 'Email Address', 'required' => false, 'allowEmpty' => true, 'validators' => array (array ('EmailAddress', true ), array ('Db_RecordExists', true, array (Engine_Db_Table::getTablePrefix () . 'users', 'email' ) ) ) ) );
			
			$types = Engine_Api::_ ()->getDbTable ( 'type', 'familymember' )->fetchAll ();
			$arr = array ('-- Select --' );
			foreach ( $types as $type ) {
				$arr [$type->type_id] = $type->title;
			}
			
			$this->addElement ( 'select', 'relation' . $i, array ('label' => 'Relation:', 'multiOptions' => $arr ) );
			
			$this->addDisplayGroup ( array ('email' . $i, 'relation' . $i ), 'texts' . $i );
		}
		
		$this->addElement ( 'Button', 'submit', array ('label' => 'Add', 'type' => 'submit', 'ignore' => true, 'decorators' => array ('ViewHelper' ) ) );
		
		$this->addElement ( 'Cancel', 'cancel', array ('label' => 'cancel', 'prependText' => ' or ', 'decorators' => array ('ViewHelper' ) ) );
		$this->addDisplayGroup ( array ('submit', 'cancel' ), 'buttons' );
	}
}